package com.member.web.controller.shop;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.member.shop.domain.SysBizActivity;
import org.springframework.security.access.prepost.PreAuthorize;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.enums.BusinessType;
import com.member.shop.domain.SysBizCouponGoods;
import com.member.shop.service.ISysBizCouponGoodsService;
import com.member.common.utils.poi.ExcelUtil;
import com.member.common.core.page.TableDataInfo;

/**
 * 【优惠券指定商品】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2024-05-08
 **/
@RestController
@RequestMapping("/shop/couponGoods")
public class SysBizCouponGoodsController extends BaseController {
    @Resource
    private ISysBizCouponGoodsService sysBizCouponGoodsService;

    private void setTenantId(SysBizCouponGoods sysBizCouponGoods) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizCouponGoods.setTenantId(tenantId);
        }
    }

    /**
     * 查询优惠券指定商品列表
     */
    @PreAuthorize("@ss.hasPermi('shop:couponGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizCouponGoods sysBizCouponGoods) {
        startPage();
        setTenantId(sysBizCouponGoods);
        List<SysBizCouponGoods> list = sysBizCouponGoodsService.selectSysBizCouponGoodsList(sysBizCouponGoods);
        return getDataTable(list);
    }

    /**
     * 导出优惠券指定商品列表
     */
    @PreAuthorize("@ss.hasPermi('shop:couponGoods:export')")
    @Log(title = "优惠券指定商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizCouponGoods sysBizCouponGoods) {

        setTenantId(sysBizCouponGoods);
        List<SysBizCouponGoods> list = sysBizCouponGoodsService.selectSysBizCouponGoodsList(sysBizCouponGoods);
        ExcelUtil<SysBizCouponGoods> util = new ExcelUtil<SysBizCouponGoods>(SysBizCouponGoods.class);
        util.exportExcel(response, list, "优惠券指定商品数据");
    }

    /**
     * 获取优惠券指定商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:couponGoods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizCouponGoodsService.selectSysBizCouponGoodsById(id));
    }

    /**
     * 新增优惠券指定商品
     */
    @PreAuthorize("@ss.hasPermi('shop:couponGoods:add')")
    @Log(title = "优惠券指定商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizCouponGoods sysBizCouponGoods) {
        return toAjax(sysBizCouponGoodsService.insertSysBizCouponGoods(sysBizCouponGoods));
    }

    /**
     * 修改优惠券指定商品
     */
    @PreAuthorize("@ss.hasPermi('shop:couponGoods:edit')")
    @Log(title = "优惠券指定商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizCouponGoods sysBizCouponGoods) {
        return toAjax(sysBizCouponGoodsService.updateSysBizCouponGoods(sysBizCouponGoods));
    }

    /**
     * 删除优惠券指定商品
     */
    @PreAuthorize("@ss.hasPermi('shop:couponGoods:remove')")
    @Log(title = "优惠券指定商品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizCouponGoodsService.deleteSysBizCouponGoodsByIds(ids));
    }
}
